<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      console.log(111)

      // 默认情况下，ws:// 使用 80 端口，wss:// 使用 443 端口
      const socket = new WebSocket('wss://192.168.31.185:8080') // 这里假设服务器端的 WebSocket 端点是 /ws-endpoint，实际需要根据服务器配置修改

      socket.onopen = function (event) {
        console.log('WebSocket 连接已打开')
      }

      socket.onmessage = function (event) {
        console.log('收到消息：', event.data)
      }

      socket.onclose = function (event) {
        console.log('WebSocket 连接已关闭')
      }

      socket.onerror = function (error) {
        console.log('WebSocket 连接出错：', error)
      }
    </script>
  </body>
</html>
